package com.csun.cmny.provider.web.rpc;

import com.google.common.collect.Lists;
import com.csun.cmny.provider.model.domain.OpcAppClock;
import com.csun.cmny.provider.model.dto.SendClockDto;
import com.csun.cmny.provider.service.OpcAppClockFeignApi;
import com.csun.cmny.provider.service.OpcAppClockService;
import com.csun.cmny.provider.service.impl.JPushService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-28 20:55
 * @Description:
 */
@Slf4j
@RestController
public class OpcAppClockFeignClient implements OpcAppClockFeignApi{

    @Resource
    private OpcAppClockService opcAppClockService;
    @Resource
    private JPushService jPushService;

    @Override
    public void sendAppClockMsg(@RequestBody SendClockDto sendClockDto) {

        log.info("sendClockDto ==> {}", sendClockDto.toString());

        /**
         * 根据符合时间的闹钟
         */
//        OpcAppClock opcAppClock = new OpcAppClock();
//        opcAppClock.setOpen(1);
//        opcAppClock.setTime(sendClockDto.getTime());
//        List<OpcAppClock> opcAppClockList = opcAppClockService.select(opcAppClock);
//        for (OpcAppClock c : opcAppClockList) {
//            log.info("app clock ==> {}", c.toString());
//            if (c.getRepeat().split("-")[sendClockDto.getIndex()].equals("1")) {
//                // 推送闹钟
//                Map map = JSONObject.fromObject(c);
//                map.put("msgType", "appClock");
//                List<String> tagList = Lists.newArrayList("userId_" + c.getUserId());
//                //
//                String sound = "sound.caf";
//                if (c.getBell().equals(1)) {
//                    sound = "lightM_1.caf";
//                }
//                jPushService.sendToAll(c.getTitle(), c.getTitle(), c.getTitle(), map.toString(), tagList, sound);
//            }
//        }

    }


}
